package com.cskaoyan;

import com.cskaoyan.connectionpool.MyConnectionPool;
import com.cskaoyan.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/03/21 17:43
 *
 * @author ciggar
 * 查询
 */
public class DatasouceJDBC {



    public static void main(String[] args) throws SQLException {

        // 从数据库连接池获取连接
        Connection connection = MyConnectionPool.getConnection();

        // 3. 获取statement对象
        Statement statement = connection.createStatement();

        // 4. 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from city");


        while (resultSet.next()) {

            String name = resultSet.getString("name");
            int id = resultSet.getInt("id");
            int pId = resultSet.getInt("p_id");
            System.out.println("name:"+ name + ",id:" + id + ",pId:" + pId);
        }

        for (int i = 0; i < 8; i++) {

            Connection connection1 = MyConnectionPool.getConnection();

        }



        // 关闭资源（注：不能关闭连接）
        JDBCUtils.close(resultSet,statement,null);

        // 返回连接到数据库连接池
        MyConnectionPool.returnConnection(connection);



    }


}
